package com.dong.pointviewpager.transformer

import android.view.View
import androidx.viewpager.widget.ViewPager.PageTransformer

/**
 * Created by Dong on 2018/3/19.
 */
class OverCardTransformer(private val mOffset: Float) : PageTransformer {

    override fun transformPage(view: View, position: Float) {
        if (position <= 0) {
            view.rotation = 45 * position
            if (view.width > view.height) view.translationX =
                view.width / 3 * position else view.translationX = view.height / 3 * position
        } else {
            view.rotation = 0.toFloat()
            //横向偏移量
            view.translationX = -view.width * position
            //缩放比例
            val scale = (view.width - mOffset * position) / view.width.toFloat()
            view.scaleX = scale
            view.scaleY = scale
            //纵向偏移量
            view.translationY = mOffset * position
        }
    }
}